/*
 * @Description:
 * @Author: dh
 * @Date: 2021-08-19 17:18:39
 * @LastEditors: dh
 * @LastEditTime: 2025-09-11 17:09:59
 */

// A 继承 B
function extend(A, B) {
	function f() {}
	f.prototype = B.prototype
	A.prototype.__proto__ = new f() //用额外构造函数的实列，而不直接用B.prototype，防止A修改B的属性和方法
	A.prototype.constructor = A
}

function A(name) {
	this.name = name
}
function B(name) {
	this.name = name
}
extend(A, B)

B.prototype.say = function () {
	console.log('b say')
}

A.prototype.eat = function () {
	console.log('a eat')
}

const a = new A('a name')

a.say()
